<?php
class permissions extends base
{
	static public $from     = 'my_permission';
	static public $fields   = array('id','title');

	public function __construct() 
	{
		$this->from		= self::$from;
		$this->fields	= self::$fields;
	}

    public function permissionsList()
    {
		$db		= self::db();
    	$query = "SELECT * from ".$this->from;
    	return $db->fetchAll($query);
    }

    public function groupList()
    {
		$db		= self::db();
    	$query = "SELECT * from my_usergroup";
    	return $db->fetchAll($query);
    }

    public function isPermission($uid, $permission)
    {
		$db		= self::db();
		$query	= $db->select()->from('my_member')->where("id='{$uid}'");
		$result	= $db->fetchRow($query);

		$query	= $db->select()->from('my_usergroup')->where("id='". $result['wid'] . "' and permission like '%,{$permission},%'");
		$result	= $db->fetchRow($query);
        if (empty($result))
        {
            return false;
        }
        return true;
    }
}
?>
